<template>
  <view>
	  <!-- 公共组件-每个页面必须引入 -->
	  <public-module></public-module>	
		<u-sticky>
			<div style="padding:24rpx;background: #fff;">
				<u-search placeholder="请输入公司名称关键字" v-model="keyword" @change="search" @search="search"></u-search>
			</div>  
		</u-sticky>
	   <div style="background: rgba(254,247,227,1);border-radius: 6px;font-size: 22rpx;color: #FF6339;padding:12rpx 50rpx;">点击搜索出的公司，即可提交关联申请</div>
	  <div class="authentication-page">
		  <div class="con-list" >
			  <div class="list-item" @click="addGl(item.companyId)" v-for="item in list">
				  {{item.companyName}}
			  </div>
			
		  </div> 
		  <div style="padding:40rpx;" v-if="status!=''">
			  <u-loadmore :status="status"></u-loadmore>
		  </div>
		  
	  </div>
  </view> 
</template>
<script>
  import {addGlCompany,companyList} from '@/config/api.js'

  export default {
    data() {
      return {
        list: [],
		status: '',
		pageNum: 0,
		pageSize:10,
		count:0,
		keyword:''
		
      }
    },
    
	onReachBottom() {
		console.log("------------")
		if(this.list.length >= this.count) {
			this.status = 'nomore';
			return ;
		}
		this.pageNum = ++ this.pageNum;
		this.getList()
	},
    onLoad(e) {
	  this.clearData();
      // this.getList()
    },
    methods: {
		addGl(id){
			addGlCompany({companyId:id}).then(()=>{
				uni.showToast({
				  title: '关联申请已提交',
				  duration: 1000,
				  icon: 'none'
				})
				uni.setStorage({
				  key: 'addGl',
				})
				setTimeout(()=>{
					uni.navigateBack();
				},1000)
				
			})
		},
		//清除数据
		clearData(){
			this.pageNum = 1;
			this.list = [];
			this.status = '';
			this.count = 0;
		},
		search(){
			if(this.keyword != ''){
				this.clearData();
				this.getList()
			}
			
		},
     
      getList(){
      	let data = {};
      	data.pageSize = 10;
      	data.pageNum = this.pageNum;
		data.companyName = this.keyword
      	this.status = 'loading';
      	companyList(data).then((res)=>{
      		this.list = this.list.concat(res.list ? res.list : [] );
      		this.count = res.count;
      		if(this.list.length >= this.count) {
      			this.status = 'nomore';
      		}else{
      			this.status = 'loadmore';
      		}
			console.log("status",this.status)
      	}).catch(()=>{
      		this.status = 'loadmore';
      	})
      },
     
    }
  }
</script>

<style lang="scss">
 @import '@/style/common.scss';
 .authentication-page{
	 padding:24rpx;
	
	.con-list{
		.list-item{
			background: rgba(255,255,255,1);
			border-radius: 18rpx;
			padding:16rpx 24rpx;
			margin-bottom:32rpx;
		    font-size:28rpx;
		}
	}
 }
 
</style>